package com.zhf.servlet.class1;

import com.zhf.entity.Class1;
import com.zhf.service.ClassService;
import com.zhf.service.impl.ClassServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "ClassUpdateServlet", urlPatterns = "/classUpdate")
public class ClassUpdateServlet extends HttpServlet {
    private ClassService classService = new ClassServiceImpl();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String classNo = request.getParameter("classNo");
        String className = request.getParameter("className");
        String grade = request.getParameter("grade");
        String headerTeacher = request.getParameter("headerTeacher");
        String classSlogan = request.getParameter("classSlogan");
        String classNumber = request.getParameter("classNumber");
        String currentPage = request.getParameter("currentPage");
        Class1 class1 = new Class1();
        class1.setClassNo(classNo);
        class1.setClassName1(className);
        class1.setGrade(grade);
        class1.setHeaderTeacher(headerTeacher);
        class1.setClassSlogan(classSlogan);
        class1.setClassNumber(Integer.parseInt(classNumber));
        int i = classService.updateClass1(class1);
        if(i > 0){
            request.setAttribute("msg", "修改成功");
            request.setAttribute("code", "100");
        }
        else{
            request.setAttribute("msg", "修改失败，未找到该班级编号！");
            request.setAttribute("code", "101");
        }
        request.setAttribute("currentPage", currentPage);
        request.getRequestDispatcher("/classQueryAll").forward(request, response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
